<form id="edu-form" lay-filter="edu-form" class="layui-form model-form">
    <input name="id" type="hidden">
    <div class="layui-form-item">
        <label class="layui-form-label">账号</label>
        <div class="layui-input-block">
            <input name="username" placeholder="请输入账号" type="text" class="layui-input" maxlength="20"
                   lay-verify="required" required/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">用户名</label>
        <div class="layui-input-block">
            <input name="nickname" placeholder="请输入用户名" type="text" class="layui-input" maxlength="20"
                   lay-verify="required" required/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">手机号</label>
        <div class="layui-input-block">
            <input name="phone" placeholder="请输入手机号" type="text" class="layui-input" lay-verify="required|phone"
                   required/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">邮件</label>
        <div class="layui-input-block">
            <input name="email" placeholder="请输入邮箱" type="text" class="layui-input" lay-verify="required|email"
                   required/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">性别</label>
        <div class="layui-input-block">
            <input type="radio" name="sex" value="0" title="男" checked/>
            <input type="radio" name="sex" value="1" title="女"/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">班主任</label>
        <div class="layui-input-block">
            <select name="teacherId" id="teacherId" lay-verify="required">
                <option value="-1"></option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">学校</label>
        <div class="layui-input-block">
            <input name="school" placeholder="请输入学校" type="text" class="layui-input" lay-verify="required|school" required/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">学历</label>
        <div class="layui-input-block">
            <input name="education" placeholder="请输入学历" type="text" class="layui-input" lay-verify="required|education" required/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">是否全日制</label>
        <div class="layui-input-block">
            <input type="radio" name="fullTime" value="1" title="是" checked/>
            <input type="radio" name="fullTime" value="0" title="否"/>
        </div>
    </div>
    <div class="layui-form-item model-form-footer">
        <button class="layui-btn layui-btn-primary" ew-event="closeDialog" type="button">取消</button>
        <button class="layui-btn" lay-filter="edu-form-submit" lay-submit>保存</button>
    </div>
</form>

<script>
    layui.use(['layer', 'admin', 'form', 'formSelects'], function () {
        var layer = layui.layer;
        var admin = layui.admin;
        var form = layui.form;
        var formSelects = layui.formSelects;

        form.render('radio');

        // 获取所有班主任
        layer.load(2);
        admin.req('api-user/teachers', {}, function (data) {
            layer.closeAll('loading');
            if (0 == data.code) {
                $.each(data.data,function(index,item){
                    $('#teacherId').append(new Option(item.nickname,item.username));//往下拉菜单里添加元素
                });

                form.render();  //菜单渲染 把内容加载进去

                // 回显数据
                var edu = admin.getTempData('t_edu');
                console.log(edu);
                $('#edu-form').attr('method', 'POST');
                if (edu) {
                    form.val('edu-form', edu);
                    $('#edu-form').attr('method', 'POST');
                    admin.putTempData('t_edu')
                }
            } else {
                layer.msg('获取角色失败', {icon: 2, time: 500});
            }
        }, 'GET');

        // debugger;


        // 表单提交事件
        form.on('submit(edu-form-submit)', function (data) {
            layer.load(2);
            admin.req('api-user/teachers/addStudent', JSON.stringify(data.field), function (data) {
                layer.closeAll('loading');
                if (data.code == 0) {
                    layer.msg(data.msg, {icon: 1, time: 500});
                    admin.finishPopupCenter();
                } else {
                    layer.msg(data.msg, {icon: 2, time: 500});
                }
            }, 'post');
            return false;
        });
    });
</script>